import 'package:flutter/material.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/common/address_bar.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/common/goods_order_info_item.dart';
import 'package:xinxuan/common/network_image_util.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:xinxuan/controllers/blind_box/blind_box_confirm_order_page_controller.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class BlindBoxConfirmOrderPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    Map<String, dynamic> mapArguments = Get.arguments;
    String image = mapArguments['image'];
    String title = mapArguments['title'];
    String price = mapArguments['price'];
    // int integral = mapArguments['integral'];
    int id = mapArguments['id'];
    return GetBuilder<BlindBoxConfirmOrderPageController>(
      init: BlindBoxConfirmOrderPageController(),
      builder: (controller) {
        return Scaffold(
          backgroundColor: pageBgColor,
          appBar: AppBarUtil(
            title: '确认订单',
            backgroundColor: pageBgColor,
          ),
          body: ScrollConfigurationCommon(child: ListView(
            children: [
              InkWellUtil.shakeProofInkWell(AddressBar(
                consignee: '${controller.addressItem.value.consignee}', 
                mobile: '${controller.addressItem.value.mobile}',
                provinceStr: '${controller.addressItem.value.provinceStr}',
                cityStr: '${controller.addressItem.value.cityStr}',
                districtStr: '${controller.addressItem.value.districtStr}',
                address: '${controller.addressItem.value.address}',
                id: controller.addressItem.value.id!
              ), () {
                Get.toNamed(
                  '${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.ADDRESS_LIST_PAGE}',
                  arguments: {
                    'isSelectAddress': true
                  }
                )!.then((res) {
                  if (res != null) {
                    controller.addressItem.value = res;
                    controller.update();
                  }
                });
              }),
              SizedBox(height: 12.h),
              Container(
                padding: EdgeInsets.symmetric(horizontal: 16.w),
                color: bgWhiteColor,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      height: 44.h,
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '商品信息',
                        style: TextStyle(
                          color: textBlackColor,
                          fontSize: 14.sp,
                          fontWeight: FontWeight.bold
                        ),
                      ),
                    ),
                    Row(
                      children: [
                        NetworkImageUtil(
                          url: image, 
                          width: 90.w, 
                          height: 90.w,
                          borderRadius: 5.w,
                        ),
                        SizedBox(width: 12.w),
                        Expanded(child: Container(
                          constraints: BoxConstraints(
                            minHeight: 90.w
                          ),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.start,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                '$title',
                                maxLines: 2,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: textBlackColor,
                                  fontSize: 14.sp
                                ),
                              ),
                              SizedBox(height: 6.h),
                              Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    '¥$price',
                                    style: TextStyle(
                                      fontSize: 18.sp,
                                      fontWeight: FontWeight.bold,
                                      color: mainTextColor
                                    ),
                                  ),
                                  Text(
                                    'x1',
                                    style: TextStyle(
                                      color: textSubtitleColor,
                                      fontSize: 14.sp
                                    ),
                                  )
                                ],
                              )
                            ],
                          ),
                        ))
                      ],
                    ),
                    SizedBox(height: 12.h)
                  ],
                ),
              ),
              SizedBox(height: 12.h),
              Container(
                color: bgWhiteColor,
                child: Column(
                  children: [
                    Container(
                      decoration: BoxDecoration(
                        border: Border(
                          bottom: BorderSide(
                            width: .5,
                            color: lineColor
                          )
                        )
                      ),
                      child: Column(
                        children: [
                          GoodsOrderInfoItem(
                            title: '商品金额', 
                            value: '¥$price',
                            valueBold: true,
                          ),
                          // GoodsOrderInfoItem(
                          //   title: '获得积分', 
                          //   value: '$integral',
                          //   valueBold: true,
                          // ),
                          SizedBox(height: 8.h)
                        ],
                      ),
                    ),
                    Container(
                      height: 54.h,
                      alignment: Alignment.centerRight,
                      padding: EdgeInsets.symmetric(horizontal: 16.w),
                      child: Text.rich(
                        TextSpan(
                          text: '应付款：',
                          style: TextStyle(
                            color: textBlackColor,
                            fontSize: 14.sp
                          ),
                          children: [
                            TextSpan(
                              text: '¥',
                              style: TextStyle(
                                color: mainTextColor,
                                fontSize: 14.sp,
                                fontWeight: FontWeight.bold
                              ),
                            ),
                            TextSpan(
                              text: '$price',
                              style: TextStyle(
                                color: mainTextColor,
                                fontSize: 18.sp,
                                fontWeight: FontWeight.bold
                              ),
                            )
                          ]
                        )
                      ),
                    )
                  ],
                ),
              )
            ],
          )),
          bottomNavigationBar: BottomAppBar(
            child: Container(
              height: 56.h,
              padding: EdgeInsets.symmetric(horizontal: 12.w),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text.rich(
                    TextSpan(
                      text: '¥',
                      style: TextStyle(
                        color: mainTextColor,
                        fontSize: 18.sp,
                        fontWeight: FontWeight.bold
                      ),
                      children: [
                        TextSpan(
                          text: '$price',
                          style: TextStyle(
                            color: mainTextColor,
                            fontSize: 22.sp,
                            fontWeight: FontWeight.bold
                          ),
                        )
                      ]
                    )
                  ),
                  Container(
                    width: 120.w,
                    child: ButtonUtil(
                      text: '提交订单', 
                      fontSize: 14.sp, 
                      borderRadius: 36.h, 
                      height: 36.h, 
                      onTop: () {
                        controller.submitOrder(id);
                      }
                    ),
                  )
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}